package cn.schoolwow.quickdao.test.module.business.user.dml.userRole.flow.delete;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickdao.test.entity.Role;
import cn.schoolwow.quickdao.test.entity.User;
import cn.schoolwow.quickdao.test.entity.UserRole;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import org.junit.Assert;

public class CheckDeleteUserRoleResultFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        checkUserCount(flowContext);
        checkRoleCount(flowContext);
        checkUserRoleCount(flowContext);
    }

    @Override
    public String name() {
        return "检查删除用户角色表结果流程";
    }

    private void checkUserCount(FlowContext flowContext){
        DAO dao = flowContext.checkInstanceData(DAO.class);

        long count = dao.query(User.class).execute().count();
        Assert.assertEquals(0, count);
    }

    private void checkRoleCount(FlowContext flowContext){
        DAO dao = flowContext.checkInstanceData(DAO.class);

        long count = dao.query(Role.class).execute().count();
        Assert.assertEquals(0, count);
    }

    private void checkUserRoleCount(FlowContext flowContext){
        DAO dao = flowContext.checkInstanceData(DAO.class);

        long count = dao.query(UserRole.class).execute().count();
        Assert.assertEquals(0, count);
    }
}
